package gameengine.com.state;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParserException;

import android.R.color;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import android.view.KeyEvent;

import gameengine.com.BitmapFont;
import gameengine.com.GameLayer;
import gameengine.com.GameLib;
import gameengine.com.IConstant;
import gameengine.com.MainActivity;
import gameengine.com.Map;
import gameengine.com.Sprite;
import gameengine.com.actor.Creature;
import gameengine.com.actor.Explorer;

public class StateLogo extends MainActivity implements IConstant {
	public static Bitmap logoBitmap = null;
	public static long timer = 0;
	public static int loadingStep = 0;
	public static int isScreen = 0;// 0 = 480;1 = 600;3 = 800

	public static synchronized void SendMessage(int type) {

		switch (type) {
		case MESSAGE_CTOR:
			logoBitmap = loadImageFromAsset("image/logo.png");
			loadingStep = 0;
			timer = System.currentTimeMillis();
			if (SCREEN_HEIGHT >= 700)
				isScreen = 3;// 3 = big;

			break;
		case MESSAGE_UPDATE:
			switch (loadingStep) {
			case 1:
				if (isScreen == 3)// = big
				{
					if (MainActivity.fontYellow == null)
						MainActivity.fontYellow = new BitmapFont(
								"font/yellow_big.spr", true);
				
				}else //
				{
					if (MainActivity.fontYellow == null)
						MainActivity.fontYellow = new BitmapFont(
								"font/yellow_small.spr", true);					
				
				}
				break;
			case 2:
				if (isScreen == 3)// = big
				{		 
					
					if (MainActivity.fontWhite == null)
						MainActivity.fontWhite = new BitmapFont(
								"font/white_big.spr", true);
				}else //
				{
					
					
					if (MainActivity.fontWhite == null)
						MainActivity.fontWhite = new BitmapFont(
								"font/white_small.spr", true);
				}
				break;
			case 3:

				break;
			case 4:

				break;
			case 5:
				if (StateMainMenu.splashBitmap == null)
					StateMainMenu.splashBitmap = loadImageFromAsset("image/splash.png");
				break;
			case 6:
				if (StateGameplay.spriteDPad == null)
					StateGameplay.spriteDPad = new Sprite(
							"sprite/ui/dpad.sprite", true);
				if (StateGameplay.spriteWall == null)
					StateGameplay.spriteWall = new Sprite(
							"sprite/deco/wall.sprite", true);
				break;
			case 7:
				bitmapScreenBuffer = Bitmap.createBitmap(800, 1280,
						Config.ARGB_4444);
				canvasScreenBuffer = new Canvas(bitmapScreenBuffer);
				break;
			default:
				break;
			}
			loadingStep++;

			if ((System.currentTimeMillis() - timer > 3500) && loadingStep > 10) {
				changeState(STATE_MAINMENU);
			}
			break;
		case MESSAGE_PAINT:

			MainActivity.mainPaint.setColor(Color.BLACK);
			MainActivity.mainPaint.setStyle(Style.FILL);
			mainCanvas.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
					MainActivity.mainPaint);
			MainActivity.mainPaint.setColor(Color.WHITE);
			MainActivity.mainPaint.setTextSize(20);
			// matrix.reset();
			// matrix.setScale(SCREEN_WIDTH*1f/1280, SCREEN_HEIGHT*1f/800);
			mainCanvas.drawBitmap(logoBitmap,
					(SCREEN_WIDTH - logoBitmap.getWidth()) / 2,
					(SCREEN_HEIGHT - logoBitmap.getHeight()) / 2 - 20,
					mainPaint);
			// mainCanvas.drawText(strString, 000, 100, mainPaint);

			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
